
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1143
 * @Author : WangRuoyu 
 * @Date : 2023/9/3 16:39
 */

#include "iostream"
#include "vector"

using namespace std;

class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        int f[text2.size() + 1][text1.size() + 1];
        for (int i = 0; i <= text2.size(); ++i) {
            for (int j = 0; j <= text1.size(); ++j) {
                f[i][j] = 0;
                if (j > 0 && i > 0) {
                    if (text2[i - 1] == text1[j - 1]) {
                        f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
                    } else {
                        f[i][j] = max(f[i - 1][j], f[i][j - 1]);
                    }
                }
            }
        }
        return f[text2.size()][text1.size()];
    }
};

int main() {
    string text1 = "abcde";
    string text2 = "ace";
    Solution sl;
    cout << sl.longestCommonSubsequence(text1, text2);
    return 0;
}